/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.util.List;
import org.lucava.boatskeeper.client.service.RoleService;
import org.lucava.boatskeeper.server.dao.MockRoleDao;
import org.lucava.boatskeeper.shared.dto.RoleDto;

/**
 *
 * @author glenn
 */
public class RoleServiceImpl extends RemoteServiceServlet implements RoleService {

    @Override
    public List<RoleDto> getRoles() {
        return MockRoleDao.getAll();
    }

    @Override
    public RoleDto getRole(Integer id) {
        return MockRoleDao.get(id);
    }

    @Override
    public Boolean saveRole(RoleDto role) {

        if (role.getId() == null) {
            MockRoleDao.add(role);
        } else {
            MockRoleDao.save(role);
        }

        return true;
    }

    @Override
    public Boolean removeRole(RoleDto role) {
        MockRoleDao.delete(role);
        return true;
    }

    @Override
    public Boolean removeRoles(List<Integer> roleIds) {

        for (Integer id : roleIds) {
            MockRoleDao.delete(MockRoleDao.get(id));
        }

        return true;
    }
}
